<?php $this->load->view('inc/header.php');?>

<?php $this->load->view('topic/inc_view_opt_bar.php');?>

<div style="padding-left: 120px;"> <div class="fl" style="width: 640px;">
	<div class="b2"></div>
	<div class="topic-view">
		
		<div class="topic-view-top">
			<a href="<?php echo site_url('c=member&m=index&id='.$r->poster->id);?>">
			<img class="topic-view-top-avatar" src="http://www.gravatar.com/avatar/<?php echo md5($r->poster->email);?>?s=60&d=&r=X"/>
			</a>
			<div class="topic-view-top-postername fs1 fb c2">
			    <?php echo $r->poster->nname;?>
			</div>
			<div class="topic-view-top-posttime c3">
				<span class="c4"><?php echo getCatFname($list_cat, $r->cat_id);?></span>
			    <?php echo date('Y-m-d H:i:s',$r->atime);?>
			</div>
			<?php if($is_login):?>
				<?php if($loginer->id != $r->poster->id):?>
				<a class="topic-view-top-follow btn-ajax <?php echo ($is_followed) ? 'followed' : '';?>" 
					afterdo="follow_afterdo" befordo="follow_befordo" 
					href="<?php echo site_url('c=member&m=follow&id='.$r->poster->id);?>"
				>
					<?php echo ($is_followed) ? '已' : '';?>关注
				</a>
				<?php endif;?>
			<?php endif;?>
		</div>
		
		<div class="b1"></div>
		
		<div class="topic-view-cont">
			<?php echo nl2br($r->smy);?>
			<div class="b1"></div>
			<?php if($r->pattern == 'img' && !empty($r->img)):?>
			<a class="cb" href="<?php echo $r->img->path;?>">
				<img style="max-width: 580px;" src="<?php echo $r->img->big_path;?>"/>
			</a>
			<?php elseif($r->pattern == 'html'):?>
			<iframe width="100%" onload="ajustH(this);" frameborder="0" scrolling="no" allowTransparency="true" src="<?php echo site_url('c=topic&m=media&id='.$r->id);?>">
			</iframe>
			<?php else:?>
			<?php endif;?>
		</div>

	</div>
	
	<?php foreach ($list_sub as $k=>$v):?>
	<div class="sub_item">
	<div class="b2"></div>
	<div class="topic-sub-view panel2 w5">
		
		<div class="topic-sub-view-top">
			<div class="topic-sub-view-top-posttime c3"><?php echo date('Y-m-d H:i:s',$v->atime);?></div>
			
			<?php if($is_login && $loginer->id == $r->poster->id):?>
			<div class="topic-sub-view-top-opt">
			<!-- 
				<a class="btn btn-6 btn-ajax-confirm" 
					msg="确定将此设为封面吗？" afterdo="topic_del_after" 
					href="<?php echo site_url('c=topic&m=cface&id='.$v->id);?>">设为封面</a>
			 -->
				
				<a class="btn btn-7 btn-ajax-confirm" 
					msg="Sure 吗 ？" afterdo="topic_del_after" 
					href="<?php echo site_url('c=topic&m=sub_del&id='.$v->id);?>">删 除</a>
			</div>
			<?php endif;?>
		</div>
		
		<div class="b1"></div>
		
		<div class="topic-sub-view-cont">
		
			<?php echo nl2br($v->smy);?>
			<div class="b1"></div>
			<?php if($v->pattern == 'img' && !empty($v->big_path)):?>
			<a class="cb" href="<?php echo $v->path;?>">
				<img style="max-width: 580px;" src="<?php echo $v->big_path;?>"/>
			</a>
			<?php elseif($v->pattern == 'html'):?>
			<iframe width="100%" onload="ajustH(this);" frameborder="0" scrolling="no" allowTransparency="true" src="<?php echo site_url('c=topic&m=media&id='.$v->id);?>">
			</iframe>
			<?php endif;?>
			
		</div>
		
	</div>
	</div>
	<?php endforeach;?>
	
	<div class="b2"></div>
	
	<?php $this->load->view('topic/inc_reply.php');?>
		
</div> 

<div class="fl" style="margin-left: 20px; width: 260px;">
	<div class="b2"></div>
	<div class="panel1">
		<h2>喜欢的人<?php echo $count_good_diger;?></h2>
		<div class="b4"></div>
		<div class="list-avatar">
		<?php foreach ($list_good_diger as $k=>$v):?>
			<a href="<?php echo site_url('c=member&m=index&id='.$v->id);?>">
			    <?php avatar($v->email,30);?>
			</a>
		<?php endforeach;?>
		</div>
	</div>
	<div class="b1"></div>
	<div class="panel1">
		<h2>收藏的人<?php echo $count_favo;?></h2>
		<div class="b4"></div>
		<div class="list-avatar">
		<?php foreach ($list_favoer as $k=>$v):?>
			<a href="<?php echo site_url('c=member&m=index&id='.$v->id);?>">
			<?php avatar($v->email,30);?>
			</a>
		<?php endforeach;?>
		</div>
	</div>
</div>
<div style="clear: both;"></div>

</div>

<?php $this->load->view('inc/footer.php');?>

<script>

function follow_afterdo(msg,$elt){

	if(msg.status == 'followed'){
		$elt.addClass('followed');
		$elt.html('').html('已关注');
	}else if(msg.status == 'unfollowed'){
		$elt.removeClass('followed');
		$elt.html('').html('关注');
	}
	
	return false;
}

function follow_befordo($elt){

	if($elt.hasClass('followed')){
	　	asyncbox.confirm('Sure 不 Sure ?','警告',function(action){
			if(action == 'ok'){
				$elt.addClass('go');				
				$elt.click();
		　　}
		});
		
		if($elt.hasClass('go')){
			$elt.removeClass('go')
			return true;
		}else{
			return false;
		}
	}

	return true;
	
}

function topic_del_after(msg,$elt){
	if(msg.status == 'succ'){
		$elt.parents('.sub_item').slideUp();
		setTimeout(function(){
			$elt.parents('.sub_item').remove();
		},500);
	}
	return false;
}

function dig_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.find('.count').empty().html(msg.data.count);
		return false;
	}
	
	return true;
}

function favo_after_do(msg,$elt){
	if(msg.status == 'succ'){
		$elt.find('.favo-count').empty().html(msg.data.count_favo);
		$elt.find('.favo-title').empty().html(msg.msg);
		return false;
	}
	
	return true;
}

</script>